package com.ruoyi.dmsIms.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.dmsIms.domain.vo.PlanInterList;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dmsIms.domain.TestPlanInter;
import com.ruoyi.dmsIms.service.ITestPlanInterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 测试计划接口Controller
 * 
 * @author ZhangSiRui
 * @date 2021-12-16
 */
@RestController
@RequestMapping("/dmsIms/inter")
public class TestPlanInterController extends BaseController
{
    @Autowired
    private ITestPlanInterService testPlanInterService;

    /**
     * 查询测试计划接口列表
     */
    @GetMapping("/list/{id}")
    public TableDataInfo list(@PathVariable("id") Long id)
    {
        List<PlanInterList> list = testPlanInterService.selectPlanInterList(id);
        return getDataTable(list);
    }

//    /**
//     * 查询测试计划接口列表
//     */
//    @GetMapping("/list")
//    public TableDataInfo list(TestPlanInter testPlanInter)
//    {
//        startPage();
//        List<TestPlanInter> list = testPlanInterService.selectTestPlanInterList(testPlanInter);
//        return getDataTable(list);
//    }

    /**
     * 导出测试计划接口列表
     */
    @Log(title = "测试计划接口", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestPlanInter testPlanInter)
    {
        List<TestPlanInter> list = testPlanInterService.selectTestPlanInterList(testPlanInter);
        ExcelUtil<TestPlanInter> util = new ExcelUtil<TestPlanInter>(TestPlanInter.class);
        util.exportExcel(response, list, "测试计划接口数据");
    }

    /**
     * 获取测试计划接口详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(testPlanInterService.selectTestPlanInterById(id));
    }

    /**
     * 新增测试计划接口
     */
//    @Log(title = "测试计划接口", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody TestPlanInter testPlanInter)
//    {
//        return toAjax(testPlanInterService.insertTestPlanInter(testPlanInter));
//    }

    @Log(title = "测试计划接口", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addlist(@RequestBody List<TestPlanInter> testPlanInters)
    {
        int count = 0;
        for (TestPlanInter testPlanInter:
             testPlanInters) {
            try{
                testPlanInterService.insertTestPlanInter(testPlanInter);
                count += 1;
            }catch (Exception e){
                logger.error(e.getMessage());
            }
        }
        return toAjax(count);
    }

    /**
     * 修改测试计划接口
     */
    @Log(title = "测试计划接口", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestPlanInter testPlanInter)
    {
        return toAjax(testPlanInterService.updateTestPlanInter(testPlanInter));
    }

//    /**
//     * 删除测试计划接口
//     */
//    @Log(title = "测试计划接口", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids)
//    {
//        return toAjax(testPlanInterService.deleteTestPlanInterByIds(ids));
//    }

    /**
     * 批量删除测试计划接口
     */
    @Log(title = "测试计划接口", businessType = BusinessType.DELETE)
    @DeleteMapping()
    public AjaxResult remove(@RequestParam("planId") Long planId, @RequestParam(value = "ids") List<Long> ids)
    {
        return toAjax(testPlanInterService.deleteTestPlanInterByInterIds(planId,ids));
    }
}
